package ar.uba.fi.tonyvaliente.commands;

import ar.uba.fi.tonyvaliente.documents.DocumentManager;

public class DumpCommand extends Command {

	private boolean recognized;
	private String path;

	public DumpCommand(String[] args) {
		super(args);

		recognized = false;
		path = null;

		if (args.length > 0) {
			String command = args[0];
			command = command.toLowerCase();
			if (command.equals("-dump")) {
				recognized = true;

				if (args.length > 1) {
					path = args[1];
				}
			}
		}
	}

	private CommandResult dump() {
		DocumentManager.dump(path);
		return CommandResult.EXECUTE_SUCCESSFULLY;
	}

	public CommandResult execute() {
		if (!recognized)
			return CommandResult.NOT_RECOGNIZED;

		return dump();
	}

	public String getSignature() {
		return "-dump [path]";
	}

	public String getDescription() {
		return "Dumps index contents to screen or file";
	}

	public String[] getExamples() {
		return new String[] { "-dump", "-dump /etc/user/dump.txt" };
	}

	public boolean isShadow() {
		return true;
	}
}
